﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManaMaple.Apollo
{
    public class AppsettingsHelper
    {
        private static IConfiguration _configuration;

        public static IConfiguration Configuration
        {
            get
            {
                if (_configuration == null)
                {
                    _configuration = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                        .Build();
                }
                return _configuration;
            }
        }
        public static void Initialize(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public static string GetConfig(string key)
        {
            var value = GetConfig<string>(key);
            return value;
        }
        public static T GetConfig<T>(string key)
        {
            T value = Configuration.GetSection(key).Get<T>();
            return value;
        }
    }
}
